﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace ServerLibForClient
{
    [Serializable]
    public class SearchRequestStruct
    {
        string serchData;
        public string SerchData
        {
            get { return serchData; }
        }

        string clientHost;
        public string ClientHost
        {
            get { return clientHost; }
        }

        string clientPort;
        public string Port
        {
            get { return clientPort; }
        }

        string sha1Hash;
        public string Sha1Hash
        {
            get { return sha1Hash; }
        }

        public SearchRequestStruct(string serchData, string clientHost, string clientPort)
        {
            this.serchData = serchData;
            this.clientHost = clientHost;
            this.clientPort = clientPort;

            sha1Hash = HashCode(serchData);
        }

        public static string HashCode(string str)
        {
            string rethash = "";
            try
            {
                System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
                System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
                byte[] combined = encoder.GetBytes(str);
                hash.ComputeHash(combined);
                rethash = Convert.ToBase64String(hash.Hash);
            }
            catch (Exception ex)
            {
                string strerr = "Error in HashCode : " + ex.Message;
            }
            return rethash;
        }  
    }
}
